/*
 * Copyright (c) Ulrich Hilger, http://dev.uhilger.de, all rights reserved.
 *
 * Published under the terms and conditions of the Apache License 2.0,
 * see http://www.apache.org/licenses/LICENSE-2.0
 */

package de.uhilger.servicehub.model;

import java.net.URL;
//import org.apache.catalina.Container;

/**
 *
 * @author Ulrich Hilger, <a href="http://dev.uhilger.de" target="_blank">http://dev.uhilger.de</a>
 * @author Published under the terms and conditions of
 * the <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Apache License 2.0</a>
 */
public interface ServletContainer {
    /** the character used to separate elements in URLS (/) */
  public static final String URL_SEPARATOR = "/";

  public static final String STOPPED = "stopped";

  public static final String CONF_DIR = "conf";
  /**
   * default name of root context
   */
  public static final String DEFAULT_ROOT = "ROOT";
  /**
   * default name of path to web applications
   */
  public static final String DEFAULT_WEBAPPS_PATH = "webapps";
  /**
   * name of localhost
   */
  public static final String LOCALHOST = "localhost";
  /**
   * character to use to separate SQL commands in a batch
   */
  public static final String SQL_CMD_SEPARATOR = ";";

  /**
   * Determine whether or not a context is already deployed on this server
   * @param contextPath  the context path to find
   * @return  true, when context path exists, false if not
   */
  boolean contextPathExists(String contextPath);

  /**
   * Registers a WAR with the container.
   *
   * @param contextPath - the context path under which the
   * application will be registered
   * @param warFile - war to deploy
   */
  void deployWAR(String contextPath, URL warFile) throws Exception;

  /**
   * Get the contexts that are currently deployed on the servlet container
   * @return  the list of deployed contexts
   */
  String[] getApps();

  /**
   * <p>Get the path of the base directory of this server, i.e. the directory
   * having directories</p>
   *
   * <p>/conf<br>
   * /logs<br>
   * /webapps<br>
   * /work<br>
   * /temp</p>
   *
   * @return - the path of the base directory
   * @see de.uhilger.servicehub.model.ServletContainer#setBase(java.lang.String)
   */
  String getBase();

  /**
   * Get the directory where to find the server binaries
   * @return  the tomcat home directory
   */
  String getHome();

  /**
   * Get information about the servlet container
   * @return  servlet container information
   */
  String getInfo();

  /**
   * Registers a WAR with the container.
   *
   * @param contextPath -
   * the context path under which the application will be
   * registered
   * @param absolutePath  path to war to register
   */
  void registerWAR(String contextPath, String absolutePath) throws Exception;

  /**
   * <p>Set base path of server instance. This is the path to a directory having
   * directories</p>
   *
   * <p>/conf<br>
   * /logs<br>
   * /webapps<br>
   * /work<br>
   * /temp</p>
   *
   * @param basePath - the path to the base directory of the server instance
   */
  void setBase(String basePath);

  /**
   * Set the directory where to find the Tomcat binaries
   * @param homePath  the tomcat home directory
   */
  void setHome(String homePath);

  /**
   * <p>Start the server, i.e. its servlet container and database server.</p>
   *
   * <p>
   * embeddedServer (Tomcat) -> engine (Catalina) -> localhost (Host) -> rootContext (Context)
   * </p>
   */
  void start(int port) throws Exception;

  /**
   * Stop the server, i.e. shut down its servlet container and database server.
   */
  void stop() throws Exception;

  /**
   * Unregisters a WAR from the web server.
   *
   * @param contextPath -
   * the context path to be removed
   */
  void unregisterWAR(String contextPath) throws Exception;

  /**
   * set the user store for this servlet container
   */
  void setUserStore(UserStore userStore);

  /**
   * Set path and name of the user database relative to getBase()
   */
  public void setUserStorageName(String storageName);

  public void setDbUser(String dbUser);

  public void setDbPassword(String dbPass);


}
